/*
 * Copyright (C) 2009 M. Hautle.
 * 
 * This file is part of TrackedBean.
 * 
 * TrackedBean is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * TrackedBean is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with TrackedBean. If not, see <http://www.gnu.org/licenses/>.
 */
package ch.trackedbean.binding.mapping;

import javax.swing.table.*;
import org.jdesktop.beansbinding.*;
import org.jdesktop.swingbinding.JTableBinding.ColumnBinding;

/**
 * Class holding infomations for a {@link ColumnBinding}.
 * 
 * @author M. Hautle
 */
public class ColumnBindingInfos extends BindingInfos {
    /** Flag indicating if the column is editable. */
    private boolean editable = true;

    /** The cellrenderer to use or null. */
    private TableCellRenderer renderer;

    /** The celleditor to use or null. */
    private TableCellEditor editor;

    /**
     * Default constructor
     * 
     * @param path The path to the the property
     */
    public ColumnBindingInfos(String path) {
        super(path);
    }

    /**
     * Default constructor
     * 
     * @param property The name of the property
     * @param converter The converter to use
     * @param sourceNullValue The source null value
     * @param sourceUnreadableValue The source unreadable value
     * @param targetNullValue The target null value
     * @param validator The validator
     */
    public ColumnBindingInfos(String property, Converter converter, Object sourceNullValue, Object sourceUnreadableValue, Object targetNullValue,
            Validator validator) {
        super(property, converter, sourceNullValue, sourceUnreadableValue, targetNullValue, validator);
    }

    /**
     * Returns if this column is editable
     * 
     * @return Returns the editable.
     */
    public boolean isEditable() {
        return editable;
    }

    /**
     * Sets the column editable/readonly.
     * 
     * @param editable True if the column is editable
     */
    public void setEditable(boolean editable) {
        this.editable = editable;
    }

    /**
     * Returns the cell renderer to use for this binding.
     * 
     * @return Returns the renderer or null
     */
    public TableCellRenderer getRenderer() {
        return renderer;
    }

    /**
     * Sets the cell renderer to use for this binding.<br>
     * Set <code>null</code> if a default renderer should be used.
     * 
     * @param renderer The renderer to set.
     */
    public void setRenderer(TableCellRenderer renderer) {
        this.renderer = renderer;
    }

    /**
     * Returns the cell editor to use for this binding.
     * 
     * @return Returns the editor or null
     */
    public TableCellEditor getEditor() {
        return editor;
    }

    /**
     * Sets the cell editor to use for this binding.<br>
     * Set <code>null</code> if a default editor should be used.
     * 
     * @param editor The editor to set.
     */
    public void setEditor(TableCellEditor editor) {
        this.editor = editor;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    void configure(Binding binding) {
        ((ColumnBinding) binding).setEditable(editable);
        super.configure(binding);
    }
}
